#include "SQLTests.h"
#include "../SQLInterface/SQLInterface.h"
#include <stdlib.h>
#include <string.h>
#include <stdio.h>

result_type send_data_test(void)
{
    tuple_t* tuple = initTuple(TABLE_STOCK_DATA);
    int i;

    // just for ease...
    for(i = 0; i < getNumParams(TABLE_STOCK_DATA); i++)
    {
        tuple->params[i] = (char*)malloc(100);
    }

    strcpy((char*)tuple->params[STOCK_DATA_PARAM_SYMBOL], "AAA");
    strcpy((char*)tuple->params[STOCK_DATA_PARAM_DATE], "1900-01-01");
    strcpy((char*)tuple->params[STOCK_DATA_PARAM_OPEN], "10.0");
    strcpy((char*)tuple->params[STOCK_DATA_PARAM_HIGH], "20.0");
    strcpy((char*)tuple->params[STOCK_DATA_PARAM_LOW], "5.0");
    strcpy((char*)tuple->params[STOCK_DATA_PARAM_CLOSE], "18.5");
    strcpy((char*)tuple->params[STOCK_DATA_PARAM_VOLUME], "53425");
    strcpy((char*)tuple->params[STOCK_DATA_PARAM_ADJ_CLOSE], "5.13");

    // TODO: do some get_data_tests??
    return SQL_insert(tuple);
}

result_type get_data_test(void)
{
    tuple_t* tuple = initTuple(TABLE_STOCK_DATA);
    node_t* list = NULL;
    int numParams;
    int i = 0;

    tuple->params[0] = (char*)malloc(2);
    strcpy((char*)(tuple->params[0]), "A");

    list = SQL_select(tuple);


    if(list)
    {
        for(;list != NULL; list = list->next)
        {
            numParams = getNumParams(((tuple_t*)(list->element))->table);
            for(i = 0; i < numParams; i++)
            {
                // TODO: add checks here
                //printf((char*)(((tuple_t*)(list->element))->params[i]));
                //printf(" ");
            }
            //printf("\n");
        }
        return SUCCESS;
    }
    else
    {
        return GENERAL_ERROR;
    }
}
